/**
 * 定时器
 */
const cron = require('node-cron')
const Blood = require('../models/Blood')
const dateDiff = require('./dateFormat').dateDiff
const date = new Date()
// 0 0 0 * * * 每天的00:00:00
// 1-59 * * * * * 每分钟的1-59s
// 更新blood表中的isOutDated字段
module.export = cron.schedule('1-59 * * * * *', async () => {
  const findResult = await Blood.find()
  // console.log(findResult)
  let length = findResult.length
  for (let i = 0; i < length; i++) {
    if (dateDiff(date, findResult[i].expireDate).days > 0) {
      Blood.findOneAndUpdate({ _id: findResult[i]._id }, { $set: { isOutdated: 1 } })
        .then(res => {
        })
    }
  }
})

